<html>
<head><meta charset="utf-8"><title>core::char::NonZeroChar (Temperature check, or something) · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html">core::char::NonZeroChar (Temperature check, or something)</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="234213710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234213710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234213710">(Apr 12 2021 at 19:10)</a>:</h4>
<p>Augh, I wrote this out twice, and zulip lost it both times. Then, I typed it out in my text editor, but zulip wouldn't let me paste it in. Not sure if these bugs are in firefox nightly or zulip, but either way... Here, I can paste it as a gist. So, here's a link to a small discussion around a potential <code>core::char::NonZeroChar</code> type. Sorry it's not a more normal thread.</p>
<p><a href="https://gist.github.com/thomcc/db9cccb5fb7b33f2b199537161fa2879">https://gist.github.com/thomcc/db9cccb5fb7b33f2b199537161fa2879</a></p>



<a name="234215087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234215087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234215087">(Apr 12 2021 at 19:21)</a>:</h4>
<p>How common is that issue (I rarely deal with FFI)? Could it be handled by a crate?</p>



<a name="234215821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234215821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234215821">(Apr 12 2021 at 19:26)</a>:</h4>
<p>I think it has several uses, and it could only be handled to a limited degree by a crate, as there are no stable (or even semi-stable) ways to define types with niches.</p>
<p>It's also moderately useful for code that doesn't do FFI but implements certain unicode algorithms (ones where this is applicable). That code currently tends to use '\0' as a sentinel value, which is less clear.</p>



<a name="234216053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234216053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234216053">(Apr 12 2021 at 19:28)</a>:</h4>
<p>The fact that it could only be handled to a limited degree by a crate makes it mostly not useful as a external crate, since at that point you might as well (in the example I gave) have <code>MyCString::push(char)</code> return <code>Result&lt;(), MyNulError&gt;</code>, rather than force users to go through (and read the docs for) a <code>NonZeroChar</code> type they wouldn't already be familiar with.</p>



<a name="234216487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234216487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234216487">(Apr 12 2021 at 19:31)</a>:</h4>
<p>Null-safety is separate from niches. chars already should have niches since they're only valid for a limited range of unicode values, adding 0 as extra niche probably doesn't add all that much more except maybe in some complex enums where the niche overlap would help?</p>



<a name="234216639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234216639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234216639">(Apr 12 2021 at 19:32)</a>:</h4>
<p>It's more that <code>Option&lt;NonZeroChar&gt;</code> is equivalent to <code>char</code> and '\0' is equivalent to None::&lt;NonZeroChar&gt;</p>



<a name="234216875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234216875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234216875">(Apr 12 2021 at 19:33)</a>:</h4>
<p>Admittedly, a big reason to have this is separate from the niche. The niche is an added benefit, that allows it to be used in more scenarios</p>



<a name="234217209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234217209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234217209">(Apr 12 2021 at 19:36)</a>:</h4>
<p>Without the niche it could be defined as an external crate, IMO it's simple enough that it wouldn't be worth using most of the time. I think the bar for "should this be in the stdlib" isn't "can this be defined externally", since there are a lot of great methods and types in the stdlib that I use all the time, which I wouldn't add a dependency on a third party crate for.</p>



<a name="234217434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234217434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234217434">(Apr 12 2021 at 19:37)</a>:</h4>
<p>(Moreover, as discussed, this <em>can't</em> be defined externally, not without giving up a property that, at least IMO, is useful)</p>



<a name="234223481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234223481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234223481">(Apr 12 2021 at 20:18)</a>:</h4>
<blockquote>
<p>#[dear_mister_rustc_give_me_a_niche(1..=0x10ffff)]</p>
</blockquote>
<p>petition to rename <code>rustc_layout_scalar_valid_range_start</code> to this</p>



<a name="234223528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234223528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234223528">(Apr 12 2021 at 20:19)</a>:</h4>
<p>actually I wonder if we could change <code>rustc_layout_scalar_valid_range_start</code> to <code>rustc_layout_scalar_valid_range</code> and have it take a range instead of an integer</p>



<a name="234227140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234227140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234227140">(Apr 12 2021 at 20:43)</a>:</h4>
<p>I think the ideal version of this takes multiple ranges. Since the real valid range for char is <code>0..0xd800 | 0xe000..0x110000</code></p>



<a name="234227146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234227146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234227146">(Apr 12 2021 at 20:43)</a>:</h4>
<p>or something like that</p>



<a name="234238056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234238056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234238056">(Apr 12 2021 at 22:06)</a>:</h4>
<p>I can't remember why, but I think there might be resistance to a niche not being a single continuous range</p>



<a name="234238318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/core%3A%3Achar%3A%3ANonZeroChar%20%28Temperature%20check%2C%20or%20something%29/near/234238318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/core.3A.3Achar.3A.3ANonZeroChar.20(Temperature.20check.2C.20or.20something).html#234238318">(Apr 12 2021 at 22:10)</a>:</h4>
<p>The resistance I remember is to allowing multiple bit patterns to represent one discriminant (like "any NAN bit pattern" or "anything with the low bit set"), and the "single continuous range" restriction was "just" an implementation restriction.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>